home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / boot / initrd.img-2.6.20-15-generic / initrd.img-2.6 / scripts / functions < prev    next >
Encoding:
Text File  |  2007-05-25  |  3.6 KB  |  237 lines

  1. # -*- shell-script -*-
  2.  
  3. _log_msg()
  4. {
  5.     if [ "$quiet" = "y" ]; then return; fi
  6.     echo "$@"
  7. }
  8.  
  9. log_success_msg()
  10. {
  11.     _log_msg "Success: $@"
  12. }
  13.  
  14. log_failure_msg()
  15. {
  16.     _log_msg "Failure: $@"
  17. }
  18.  
  19. log_warning_msg()
  20. {
  21.     _log_msg "Warning: $@"
  22. }
  23.  
  24. log_begin_msg()
  25. {
  26.     if [ -x /sbin/usplash_write ]; then
  27.         /sbin/usplash_write "TEXT $@"
  28.     fi
  29.     _log_msg "Begin: $@ ..."
  30. }
  31.  
  32. log_end_msg()
  33. {
  34.     if [ -x /sbin/usplash_write ]; then
  35.         /sbin/usplash_write "SUCCESS ok"
  36.     fi
  37.     _log_msg "Done."
  38.     update_progress
  39. }
  40.  
  41. update_progress()
  42. {
  43.     [ -d /dev/.initramfs ] || return
  44.  
  45.     if [ -z "$PROGRESS_STATE" ]; then
  46.         export PROGRESS_STATE=0
  47.     fi
  48.  
  49.     PROGRESS_STATE=$(($PROGRESS_STATE + 1))
  50.     echo "PROGRESS_STATE=${PROGRESS_STATE}" > /dev/.initramfs/progress_state
  51.  
  52.     if [ -x /sbin/usplash_write ]; then
  53.         /sbin/usplash_write "PROGRESS $PROGRESS_STATE"
  54.     fi
  55. }
  56.  
  57. panic()
  58. {
  59.     if [ -x /sbin/usplash_write ]; then
  60.         /sbin/usplash_write "QUIT"
  61.     fi
  62.     # Disallow console access
  63.     if [ "${panic}" = 0 ]; then
  64.         reboot
  65.     fi
  66.     modprobe -q i8042
  67.     modprobe -q atkbd
  68.     echo $@
  69.     PS1='(initramfs) ' /bin/sh -i </dev/console >/dev/console 2>&1
  70. }
  71.  
  72. maybe_break()
  73. {
  74.     if [ x$1 = x${break} ]; then
  75.         panic "Spawning shell within the initramfs"
  76.     fi
  77. }
  78.  
  79. render()
  80. {
  81.     eval "echo -n \${$@}"
  82. }
  83.  
  84. set_initlist()
  85. {
  86.     unset initlist
  87.     for si_x in ${initdir}/*; do
  88.         if [ ! -x ${si_x} ]; then
  89.             continue
  90.         fi
  91.         initlist="${initlist} ${si_x#${initdir}/}"
  92.     done
  93. }
  94.  
  95. reduce_satisfied()
  96. {
  97.     deplist="$(render array_${1})"
  98.     unset tmpdeplist
  99.     for rs_y in ${deplist}; do
  100.         if [ ! -f ${initdir}/${rs_y} ]; then
  101.             continue
  102.         fi
  103.         tmpdeplist="${tmpdeplist} ${rs_y}"
  104.     done
  105.     deplist=${tmpdeplist}
  106.     for rs_x in ${runlist}; do
  107.         pop_list_item ${rs_x} ${deplist}
  108.         deplist=${tmppop}
  109.     done
  110.     eval array_${1}=\"${deplist}\"
  111. }
  112.  
  113. get_prereqs()
  114. {
  115.     set_initlist
  116.     for gp_x in ${initlist}; do
  117.         tmp=$(${initdir}/${gp_x} prereqs)
  118.         eval array_${gp_x}=\"${tmp}\"
  119.     done
  120. }
  121.  
  122. count_unsatisfied()
  123. {
  124.     set -- ${@}
  125.     return ${#}
  126. }
  127.  
  128. # Removes $1 from initlist
  129. pop_list_item()
  130. {
  131.     item=${1}
  132.     shift
  133.     set -- ${@}
  134.     unset tmppop
  135.     # Iterate
  136.     for pop in ${@}; do
  137.         if [ ${pop} = ${item} ]; then
  138.             continue
  139.         fi
  140.         tmppop="${tmppop} ${pop}"
  141.     done
  142.  
  143. }
  144.  
  145. # This function generates the runlist, so we clear it first.
  146. reduce_prereqs()
  147. {
  148.     unset runlist
  149.     set_initlist
  150.     set -- ${initlist}
  151.     i=$#
  152.     # Loop until there's no more in the queue to loop through
  153.     while [ ${i} -ne 0 ]; do
  154.         oldi=${i}
  155.         for rp_x in ${initlist}; do
  156.             reduce_satisfied ${rp_x}
  157.             count_unsatisfied $(render array_${rp_x})
  158.             cnt=${?}
  159.             if [ ${cnt} -eq 0 ]; then
  160.                 runlist="${runlist} ${rp_x}"
  161.                 pop_list_item ${rp_x} ${initlist}
  162.                 initlist=${tmppop}
  163.                 i=$((${i} - 1))
  164.             fi
  165.         done
  166.         if [ ${i} -eq ${oldi} ]; then
  167.             panic "PANIC: Circular dependancy.  Exiting."
  168.         fi
  169.     done
  170. }
  171.  
  172. call_scripts()
  173. {
  174.     for cs_x in ${runlist}; do
  175.         # mkinitramfs verbose output
  176.         if [ "${verbose}" = "y" ]; then
  177.             echo "Calling hook ${cs_x}"
  178.         fi
  179.         ${initdir}/${cs_x}
  180.         # allow boot scripts to modify exported boot paramaters
  181.         if [ -e /conf/param.conf ]; then
  182.             . /conf/param.conf
  183.         fi
  184.     done
  185. }
  186.  
  187. run_scripts()
  188. {
  189.     initdir=${1}
  190.     get_prereqs
  191.     reduce_prereqs
  192.     call_scripts
  193. }
  194.  
  195. # Load custom modules first
  196. load_modules()
  197. {
  198.     if [ -e /conf/modules ]; then
  199.         cat /conf/modules | while read m; do
  200.             # Skip empty lines
  201.             if [ -z "$m" ];  then
  202.                 continue
  203.             fi
  204.             # Skip comments - d?ash removes whitespace prefix
  205.             com=$(printf "%.1s" "${m}")
  206.             if [ "$com" = "#" ]; then
  207.                 continue
  208.             fi
  209.             modprobe -q $m
  210.         done
  211.     fi
  212. }
  213.  
  214. # lilo compatibility
  215. parse_numeric() {
  216.     case $1 in
  217.     "")
  218.         return
  219.         ;;
  220.     /*)
  221.         return
  222.         ;;
  223.     *:*)
  224.         minor=${1#*:}
  225.         major=${1%:*}
  226.         ;;
  227.     *)
  228.         value=$(( 0x${1} ))
  229.         minor=$(( ${value} % 256 ))
  230.         major=$(( ${value} / 256 ))
  231.         ;;
  232.     esac
  233.  
  234.     mknod /dev/root b ${major} ${minor}
  235.     ROOT=/dev/root
  236. }
  237.